﻿using System.Web.Mvc;

namespace Nop.Web.Framework.Mvc
{

    /// <summary>
    /// 对来自浏览器中Post/Get提交到服务器端指定的Action的时候
    /// 进行Model的配置工作  如下代码 就体现了将客户端的数据 实例化成服务端的Model
    ///    public ActionResult Create([Bind(Include = "Name, Sex, Birthday")] Person person) 
            ////2     { 
            ////3         // ... 
            ////4     } 
            ////5     public ActionResult Create([Bind(Exclude = "ID")] Person person) 
            ////6     { 
            ////7         // ... 
            ////8     }
    /// </summary>
    public class NopModelBinder : DefaultModelBinder
    {
        public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var model = base.BindModel(controllerContext, bindingContext);
            if (model is BaseNopModel)
            {
                ((BaseNopModel)model).BindModel(controllerContext, bindingContext);
            }
            return model;
        }

        protected override System.ComponentModel.PropertyDescriptorCollection GetModelProperties(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            bindingContext.PropertyFilter = new System.Predicate<string>(pred);
            var values = base.GetModelProperties(controllerContext, bindingContext);
            return values;
        }

        protected bool pred(string target)
        {
            return true;
        }
    }
}
